#include "led_array_driver.h"

struct gpio_info{
	GPIO_TypeDef* GPIOx;
	GPIO_Pin_TypeDef GPIO_Pin;
};

const struct gpio_info gpio_array[] ={
	{L1_PORT, L1_PIN},
	{L2_PORT, L2_PIN},
	{L3_PORT, L3_PIN},
	{L4_PORT, L4_PIN},
	{L5_PORT, L5_PIN},
	{L6_PORT, L6_PIN},
	{L7_PORT, L7_PIN},
	{L8_PORT, L8_PIN},
	{L9_PORT, L9_PIN},
	{L10_PORT, L10_PIN},
	{L11_PORT, L11_PIN},
};

int ledArray_GpioInit(void){
	int i = 0;
	for(i =0 ;i<sizeof(gpio_array)/sizeof(gpio_array[0]);i++){
		GPIO_Init(gpio_array[i].GPIOx,gpio_array[i].GPIO_Pin,GPIO_MODE_OUT_PP_HIGH_FAST);
		GPIO_WriteLow(gpio_array[i].GPIOx,gpio_array[i].GPIO_Pin);
	}
	return 0;
}


int ledArray_Refresh(unsigned short led_dot_array,unsigned char mask_dot_num){
	int i;
	if(mask_dot_num >11)
		mask_dot_num = 11;
	for(i = 0;i<mask_dot_num;i++){
		if(( led_dot_array & (unsigned short)(1<<i) ) ){
			GPIO_WriteHigh(gpio_array[i].GPIOx,gpio_array[i].GPIO_Pin);
		}else{
			GPIO_WriteLow(gpio_array[i].GPIOx,gpio_array[i].GPIO_Pin);
		}
	}

}

